package com.ews.onlineexchange.exception;

import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @program: SdewsOnlineExchange_dys
 * @description: 异常页面重定向类
 * @author: wangchangqing
 * @create: 2020-11-19 10:37
 **/
public class ExceptionRedirector {
    public void entityNotFoundExcepetionHandle(){
        FacesContext context = FacesContext.getCurrentInstance();
        ExternalContext externalContext = context.getExternalContext();
        externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
        try {
            externalContext.redirect("/404.xhtml");
            context.responseComplete();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void fileNotFoundExcepetionHandle(){
        FacesContext context = FacesContext.getCurrentInstance();
        ExternalContext externalContext = context.getExternalContext();
        externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
        try {
            externalContext.redirect("/404.xhtml");
            context.responseComplete();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
